<?php
class m_public_function extends CI_Model {
	
	function _menus(){
		if ($_SESSION[SESSION_GROUPID] == -1){
		$sql ="select s_menus.* from s_menus 
				where menus_sys_active =  1
				order by menus_parent, menus_seq";
		}else{
		$sql = "select s_menus.* from s_role 
				left join s_menus on menus_id = s_menus_id
				where s_usergroups_id =  '".$_SESSION[SESSION_GROUPID]."'
				and menus_sys_active =  1
				order by menus_parent,menus_seq ";
		}
		$query = $this->db->query($sql);
		$result = array();
		foreach($query->result() as $row){
			$result[$row->menus_parent][] = $row;
		}
		return $result;
	}
	
	function _main_menus(){
		if ($_SESSION[SESSION_GROUPID] == -1){
		$sql ="select parent.* from
				s_menus as node 
				left join s_menus as parent on parent.menus_id = node.menus_parent
				and node.menus_sys_active =  1
				where node.menus_parent <> -1
				group by node.menus_parent
				order by parent.menus_seq";
		}else{
		$sql = "select parent.* from s_role 
				left join s_menus as node on node.menus_id = s_menus_id
				left join s_menus as parent on parent.menus_id = node.menus_parent
				where s_usergroups_id = '".$_SESSION[SESSION_GROUPID]."'
				and node.menus_sys_active =  1
				group by node.menus_parent
				order by parent.menus_seq";
		}
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
}